/*
 * @(#)AbstractMetaObject.java	1.0 2000/12/28
 *
 * Copyright 2000 Thomas Barnekow. All Rights Reserved.
 *
 * This software is the proprietary information of Thomas Barnekow.
 * Use is subject to license terms.
 */

package tb.provider;

/**
 * This is an abstract base class for {@link MetaObject}s.
 *
 * @author Thomas Barnekow
 * @version 1.0
 */
public abstract class AbstractMetaObject implements MetaObject {

  /**
   * This {@link MetaObject}'s id.
   */
  private Comparable m_id;

  /**
   * This {@link MetaObject}'s container.
   */
  private CompoundMetaObject m_container;

  /**
   * Create an uncontained {@link MetaObject}.
   */
  public AbstractMetaObject(Comparable id) {
    this(id, null);
  }

  /**
   * Create a {@link MetaObject} that is contained in the given <code>container</code>.
   */
  public AbstractMetaObject(Comparable id, CompoundMetaObject container) {
    if (id == null) {
      throw new NullPointerException("A MetaObject's id must not be null");
    }
    m_id = id;
    m_container = container;
  }

  /*
   * MetaObject operations
   */

  public Comparable getId() {
    return m_id;
  }

  public CompoundMetaObject getContainer() {
    return m_container;
  }

  /**
   * This default implementation just throws an
   * {@link java.lang.UnsupportedOperationException}.
   *
   * @exception UnsupportedOperationException in any case
   */
  public Object getDeclaration() {
    throw new UnsupportedOperationException();
  }

  /*
   * Comparable operations
   */

  public int compareTo(Object o) {
    if (o instanceof MetaObject)
      return m_id.compareTo(((MetaObject) o).getId());
    else
      throw new ClassCastException();
  }

  /*
   * Object operations
   */

	public boolean equals(Object o) {
    return compareTo(o) == 0;
	}

	public int hashCode() {
		return m_id.hashCode();
	}

	public String toString() {
    return m_id.toString();
	}
}